//    Copyright (C) Kherty.  All rights reserved.
using System.Windows.Media;
using OpenLS.Core.Serialization;
using OpenLS.Spreadsheet.Office2003;

namespace OpenLS.Spreadsheet
{
    partial class Borders: IOffice2003XmlSerializable
    {
        void IOffice2003XmlSerializable.ReadXmlSpreadsheet(ReadContext context)
        {
            using (ReadContext c = context.Read("Borders"))
            {
                while (c.ReaderLocalName == "Border")
                {
                    using (ReadContext cb = c.Read("Border"))
                    {
                        BorderPosition position = cb.GetEnum<BorderPosition>(cb.Namespace + "Position");
                        Border prop = new Border();
                        string color = cb.GetOptionalString(cb.Namespace + "Color");
                        if (color != null)
                            prop.Color = new RgbColor((Color)ColorConverter.ConvertFromString(color)); //\\other colors
                        LineStyle ls = cb.GetOptionalEnum(cb.Namespace + "LineStyle", LineStyle.None);
                        prop.Style = (BorderStyle)ls;
                        //\\prop. todo : thickness

                        switch (position)
                        {
                            case BorderPosition.Left: Left = prop; break;
                            case BorderPosition.Right: Right = prop; break;
                            case BorderPosition.Top: Top = prop; break;
                            case BorderPosition.Bottom: Bottom = prop; break;
                            case BorderPosition.DiagonalLeft: DiagonalDown = prop; break; //\\sure?
                            case BorderPosition.DiagonalRight: DiagonalUp = prop; break;

                        }

                    }
                }
            }
        }
    }
}
